package com.patterns.proxy.commonDynamicProxy.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by Xiao Yiyun on 2017/4/24.
 * 动态代理的Handler类
 */
public class MyInvocationHandler implements InvocationHandler {
    //被代理的对象
    private Object object = null;
    //通过构造函数传递一个对象
    public MyInvocationHandler(Object object) {
        this.object = object;
        System.out.println("coming MyInvocationHandler constructor");
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //执行被代理的方法
        System.out.println("coming invoke");
        return method.invoke(this.object, args);
    }
}
